

import Ol_Style from 'ol/style/style';
import Ol_Style_Stroke from 'ol/style/stroke';
import Ol_Style_Fill from 'ol/style/fill';
import Ol_Style_Circle from 'ol/style/circle';

import Ol_Geom_GeometryType from 'ol/geom/geometrytype';

export class DefaultStyle {

    private _colors: number[][] = [
        [197, 108, 240, 1],
        [255, 184, 184, 1],
        [255, 56, 56, 1],
        [255, 159, 26, 1],
        [255, 242, 0, 1],
        [58, 227, 116, 1],
        [103, 230, 220, 1],
        [23, 192, 235, 1],
        [113, 88, 226, 1],
        [61, 61, 61, 1],
        [16, 142, 233, 1]
    ];
    private _styles: { [id: string]: any } = {};
    private _fill_color: number[] = [16, 142, 233, 1];
    private _line_color: number[] = [255, 255, 255, 1];
    private _polygon_line_width: number = 2;
    private _point_width: number = 3;
    private _zIndex: number = 0;

    constructor(index: number, highlight: boolean = false) {
        this._fill_color = this._colors[index];
        if(highlight) {
            this._line_color = [255, 0, 0, 1];
            this._zIndex = 9999999;
        }
        this._styles[Ol_Geom_GeometryType.POLYGON] = this._polygon();
        this._styles[Ol_Geom_GeometryType.MULTI_POLYGON] = this._styles[Ol_Geom_GeometryType.POLYGON];
        this._styles[Ol_Geom_GeometryType.POINT] = this._point();
        this._styles[Ol_Geom_GeometryType.MULTI_POINT] = this._styles[Ol_Geom_GeometryType.POINT];
        this._styles[Ol_Geom_GeometryType.LINE_STRING] = this._lineString();
        this._styles[Ol_Geom_GeometryType.MULTI_LINE_STRING] = this._styles[Ol_Geom_GeometryType.LINE_STRING];
        this._styles[Ol_Geom_GeometryType.GEOMETRY_COLLECTION] = [
            this._styles[Ol_Geom_GeometryType.POLYGON],
            this._styles[Ol_Geom_GeometryType.POINT],
            this._styles[Ol_Geom_GeometryType.LINE_STRING]
        ];
    }

    private _polygon(): any {
        return new Ol_Style({
            fill: new Ol_Style_Fill({
                color: this._fill_color
            }),
            stroke: new Ol_Style_Stroke({
                color: this._line_color,
                width: this._polygon_line_width
            }),
            zIndex: this._zIndex
        });
    }

    private _point(): any {
        return new Ol_Style({
            image: new Ol_Style_Circle({
                radius: this._point_width * 2,
                fill: new Ol_Style_Fill({
                    color: this._fill_color
                }),
                stroke: new Ol_Style_Stroke({
                    color: this._line_color,
                    width: this._point_width / 2
                })
            }),
            zIndex: this._zIndex
        });
    }

    private _lineString(): any {
        return new Ol_Style({
            stroke: new Ol_Style_Stroke({
                color: this._line_color,
                width: this._polygon_line_width
            }),
            zIndex: this._zIndex
        });
    }

    style(geometrytype: string): any {
        return this._styles[geometrytype];
    }
}